// pages/openquick/index.js
var utl = require('../../utils/util.js');
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showmesscode:false,
    cardinfo:{},
    user:'',
    credit:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var uinfos = app.globalData.loginresult;
    this.setData({
      user: uinfos.NAME,
      credit: uinfos.CADR_ID
    })
  },
  //短信确认
  commitbankmess: function (e) {
    this.setData({
      bankms: e.detail.value
    })
  },
  //关闭alt
  cancleAlt: function () {
    this.setData({
      showmesscode: false,
    })
  },
  //验证码确认请求
  surebtn: function () {
    var bks = this.data.bankms; //短信确认
    var card = this.data.bankNum;
    if (bks == '' && bks == undefined) {
      wx.showToast({
        title: '短信验证码不能为空',
        icon: 'none',
        duration: 2000
      })
      return;
    }
    wx.showLoading({
      title: '提交中...',
    })
    utl.serverToken('USER_BINDCARD_CONFIRM', {
      'CARD_NO': card,
      'FRONT_URL': '',
      'SMS_CODE': bks
    }, (err, res) => {
      wx.hideLoading();
      if (err) {
        wx.showToast({
          title: err,
          icon: 'none',
          duration: 2000
        })
        return;
      }
      wx.showModal({
        title: '提示',
        content: res.MSG,
        showCancel: false
      })
    })

  },
  usernameA:function(e){
    var userName = e.detail.value;
    this.setData({
      user:userName,
    })
  },
  creditnumberA:function(e){
    this.setData({
      credit:e.detail.value
    })
  },
  bankNumbA:function(e){
    var vle = e.detail.value;
    this.setData({
      bankNum: vle,
    })
    this.checkcardnum(vle);

  },
  //查询银行卡bin信息
  checkcardnum:function(e){
    wx.showLoading({
      title: '请求中...',
    })
    utl.serverToken('USER_CARD_BIN', {
      'CARD_NO': e
    }, (err, res) => {
      wx.hideLoading();
      if (err) {
        wx.showToast({
          title: err,
          icon: 'none',
          duration: 2000
        })
        return;
      }
      this.setData({
        cardinfo:res
      })
    })
  },
  cvnA:function(e){
    this.setData({
      cvn:e.detail.value
    })
  },
  validateA:function(e){
    this.setData({
      validate:e.detail.value
    })
  },
  telA:function(e){
    this.setData({
      tel: e.detail.value
    })
  },
  //提交
  uploadAction:function(){
    var name = this.data.user;
    var cred =this.data.credit;
    var banknum = this.data.bankNum;
    var cc = this.data.cvn;
    var validate = this.data.validate;
    var telp = this.data.tel;
    if(name == '' ||cred==''||banknum==''||cc==''||validate==''||telp==''){
      wx.showToast({
        title: '信息不全，请填充完整再提交',
        icon:'none',
        duration:2000
      })
      return;
    }
    wx.showLoading({
      title: '提交中...',
    })
    utl.serverToken('USER_BINDCARD', {
      'CARD_NO': banknum,
      'ACCOUNT_NAME': name,
      'CARD_TYPE': '1',
      'ID_CARD': cred,
      'MOBILE': telp,
      'CVN2': cc,
      'EXPIRED': validate
    }, (err, res) => {
      wx.hideLoading();
      if (err) {
        wx.showToast({
          title: err,
          icon: 'none',
          duration: 2000
        })
        return;
      }
      if (res.STATUS == 4) {
        wx.showModal({
          title: '提示',
          content: res.MSG,
          showCancel: false,
          success(res) {
            that.setData({
              showmesscode: true
            })
          }
        })
      } else {
       wx.showModal({
         title: '提示',
         content: res.MSG,
         showCancel:false
       })
      }
    })
  },
  showcard:function(){
    var cur = this.data.cardshow;
    cur = !cur;
    this.setData({
      cardshow:cur,
    })
  },
  selctcard:function(e){
    this.setData({
      cardshow: false,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})